<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for components\uploader\upload-helper.js</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="../../prettify.css" />
    <link rel="stylesheet" href="../../base.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type='text/css'>
        .coverage-summary .sorter {
            background-image: url(../../sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class='wrapper'>
  <div class='pad1'>
    <h1>
      <a href="../../index.html">all files</a> / <a href="index.html">components/uploader/</a> upload-helper.js
    </h1>
    <div class='clearfix'>
      <div class='fl pad1y space-right2'>
        <span class="strong">13.16% </span>
        <span class="quiet">Statements</span>
        <span class='fraction'>15/114</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Branches</span>
        <span class='fraction'>0/71</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Functions</span>
        <span class='fraction'>0/20</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">13.51% </span>
        <span class="quiet">Lines</span>
        <span class='fraction'>15/111</span>
      </div>
    </div>
  </div>
  <div class='status-line low'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">// 判断变量类型
const ObjToString = Object.prototype.toString
export function getType(obj) <span class="fstat-no" title="function not covered" >{</span>
<span class="cstat-no" title="statement not covered" >  if (typeof obj !== 'object') {</span>
<span class="cstat-no" title="statement not covered" >    return typeof obj</span>
  }
  let objType = <span class="cstat-no" title="statement not covered" >ObjToString.call(obj)</span>
<span class="cstat-no" title="statement not covered" >  return objType.slice(8, -1).toLowerCase()</span>
}
const isObject = obj =&gt; <span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >obj &amp;&amp; typeof obj === 'object'</span></span>
const assertTypeEqual = (obj, typeStr) =&gt; <span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >getType(obj) === typeStr</span></span>
// 处理ajax上传文件
const getError = (action, xhr) =&gt; <span class="fstat-no" title="function not covered" >{</span>
  let msg
<span class="cstat-no" title="statement not covered" >  if (xhr.response) {</span>
<span class="cstat-no" title="statement not covered" >    msg = `${xhr.response.error || xhr.response}`</span>
  } else <span class="cstat-no" title="statement not covered" >if (xhr.responseText) {</span>
<span class="cstat-no" title="statement not covered" >    msg = `${xhr.responseText}`</span>
  } else {
<span class="cstat-no" title="statement not covered" >    msg = `fail to post ${action} ${xhr.status}`</span>
  }
  const err = <span class="cstat-no" title="statement not covered" >new Error(msg)</span>
<span class="cstat-no" title="statement not covered" >  err.status = xhr.status</span>
<span class="cstat-no" title="statement not covered" >  err.method = 'post'</span>
<span class="cstat-no" title="statement not covered" >  err.url = action</span>
<span class="cstat-no" title="statement not covered" >  return err</span>
}
const getBody = xhr =&gt; <span class="fstat-no" title="function not covered" >{</span>
  const text = <span class="cstat-no" title="statement not covered" >xhr.responseText || xhr.response</span>
<span class="cstat-no" title="statement not covered" >  if (!text) {</span>
<span class="cstat-no" title="statement not covered" >    return text</span>
  }
<span class="cstat-no" title="statement not covered" >  try {</span>
<span class="cstat-no" title="statement not covered" >    return JSON.parse(text)</span>
  } catch (e) {
<span class="cstat-no" title="statement not covered" >    return text</span>
  }
}
&nbsp;
export function uploadHelper(options) <span class="fstat-no" title="function not covered" >{</span>
<span class="cstat-no" title="statement not covered" >  if (assertTypeEqual(XMLHttpRequest, 'undefined')) {</span>
<span class="cstat-no" title="statement not covered" >    return</span>
  }
  // options为对象类型
<span class="cstat-no" title="statement not covered" >  if (!isObject(options)) {</span>
<span class="cstat-no" title="statement not covered" >    return</span>
  }
  const xhr = <span class="cstat-no" title="statement not covered" >new XMLHttpRequest()</span>
  const action = <span class="cstat-no" title="statement not covered" >options.action</span>
  const formData = <span class="cstat-no" title="statement not covered" >new FormData()</span>
<span class="cstat-no" title="statement not covered" >  formData.append(options.filename, options.file)</span>
<span class="cstat-no" title="statement not covered" >  if (xhr.upload) {</span>
<span class="cstat-no" title="statement not covered" >    xhr.upload.onprogress = function progress(e) <span class="fstat-no" title="function not covered" >{</span></span>
<span class="cstat-no" title="statement not covered" >      if (e.total &gt; 0) {</span>
<span class="cstat-no" title="statement not covered" >        e.percentage = Math.floor((e.loaded / e.total) * 100)</span>
      }
<span class="cstat-no" title="statement not covered" >      options.onProgress(e)</span>
    }
  }
<span class="cstat-no" title="statement not covered" >  xhr.onerror = function error(e) <span class="fstat-no" title="function not covered" >{</span></span>
<span class="cstat-no" title="statement not covered" >    options.error(e)</span>
  }
<span class="cstat-no" title="statement not covered" >  xhr.onload = function onload() <span class="fstat-no" title="function not covered" >{</span></span>
<span class="cstat-no" title="statement not covered" >    if (xhr.status &lt; 200 || xhr.status &gt;= 300) {</span>
<span class="cstat-no" title="statement not covered" >      return options.error(getError(action, xhr))</span>
    }
<span class="cstat-no" title="statement not covered" >    options.onSuccess(getBody(xhr))</span>
  }
&nbsp;
<span class="cstat-no" title="statement not covered" >  xhr.open('post', action, true)</span>
  // 判断是否发送cookie估算
<span class="cstat-no" title="statement not covered" >  if (options.withCredentials &amp;&amp; 'withCredentials' in xhr) {</span>
<span class="cstat-no" title="statement not covered" >    options.withCredentials = true</span>
  }
&nbsp;
  const headers = <span class="cstat-no" title="statement not covered" >options.headers || {}</span>
&nbsp;
<span class="cstat-no" title="statement not covered" >  for (let key in headers) {</span>
<span class="cstat-no" title="statement not covered" >    if (headers.hasOwnProperty(key) &amp;&amp; headers[key] !== null) {</span>
<span class="cstat-no" title="statement not covered" >      xhr.setRequestHeader(key, headers[key])</span>
    }
  }
<span class="cstat-no" title="statement not covered" >  xhr.send(formData)</span>
<span class="cstat-no" title="statement not covered" >  return xhr</span>
}
&nbsp;
// 异步加载图片
export const loadImageAsync = (src, resolve, reject) =&gt; <span class="fstat-no" title="function not covered" >{</span>
  let image = <span class="cstat-no" title="statement not covered" >new Image()</span>
<span class="cstat-no" title="statement not covered" >  image.src = src</span>
<span class="cstat-no" title="statement not covered" >  image.onload = function() <span class="fstat-no" title="function not covered" >{</span></span>
<span class="cstat-no" title="statement not covered" >    resolve({</span>
      naturalHeight: image.naturalHeight, // 图片的原始大小与图片设置的大小无关
      naturalWidth: image.naturalWidth,
      src: image.src
    })
  }
<span class="cstat-no" title="statement not covered" >  image.onerror = function(e) <span class="fstat-no" title="function not covered" >{</span></span>
<span class="cstat-no" title="statement not covered" >    reject(e)</span>
  }
}
// 文件类型以及大小等相关工具函数
export const imageFileExtension = ['jpeg', 'jpg', 'png', 'gif', 'bmp']
export const docFileExtension = ['doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx', 'pdf', 'txt']
export const fileExtensionIconClass = {
  doc: 'word-file',
  docx: 'word-file',
  ppt: 'ppt-file',
  pptx: 'ppt-file',
  xls: 'xls-file',
  xlsx: 'xls-file',
  pdf: 'pdf-file',
  txt: 'txt-file',
  image: 'image-file',
  file: 'wenjian-file'
}
// 得到文件类型
export function getFileType(fileName = '') <span class="fstat-no" title="function not covered" >{</span>
<span class="cstat-no" title="statement not covered" >  if (!assertTypeEqual(fileName, 'string')) {</span>
<span class="cstat-no" title="statement not covered" >    return ''</span>
  }
  let pos = <span class="cstat-no" title="statement not covered" >fileName.lastIndexOf('.')</span>
<span class="cstat-no" title="statement not covered" >  if (pos &gt; 0) {</span>
<span class="cstat-no" title="statement not covered" >    return fileName.slice(pos + 1).toLowerCase()</span>
  }
<span class="cstat-no" title="statement not covered" >  return ''</span>
}
// 尺寸定义
const KB = 1024
const MB = 1024 * KB
const GB = 1024 * MB
const SIZE = {
  KB,
  MB,
  GB
}
export const SIZE_UNIT = ['KB', 'MB', 'GB']
const decimal = 2
// 返回文件大小字符串表示
export function fileSizeToUnit(fileSize = 0) <span class="fstat-no" title="function not covered" >{</span>
<span class="cstat-no" title="statement not covered" >  if (!assertTypeEqual(fileSize, 'number')) {</span>
<span class="cstat-no" title="statement not covered" >    return 0</span>
  }
<span class="cstat-no" title="statement not covered" >  if (fileSize &lt; 0) {</span>
<span class="cstat-no" title="statement not covered" >    fileSize = 0</span>
  }
<span class="cstat-no" title="statement not covered" >  if (fileSize &gt; GB) {</span>
<span class="cstat-no" title="statement not covered" >    return (fileSize / GB).toFixed(decimal) + 'GB'</span>
  }
&nbsp;
<span class="cstat-no" title="statement not covered" >  if (fileSize &gt; MB) {</span>
<span class="cstat-no" title="statement not covered" >    return (fileSize / MB).toFixed(decimal) + 'MB'</span>
  }
&nbsp;
<span class="cstat-no" title="statement not covered" >  if (fileSize &gt; KB) {</span>
<span class="cstat-no" title="statement not covered" >    return (fileSize / KB).toFixed(decimal) + 'KB'</span>
  }
<span class="cstat-no" title="statement not covered" >  return fileSize.toFixed(decimal) + 'BT'</span>
}
&nbsp;
// 判断文件大小是否超过限制
export function isExceedSizeLimit(fileSize, limit = 10, unit = 'MB') <span class="fstat-no" title="function not covered" >{</span>
<span class="cstat-no" title="statement not covered" >  if (!assertTypeEqual(fileSize, 'number')) {</span>
<span class="cstat-no" title="statement not covered" >    return true</span>
  }
<span class="cstat-no" title="statement not covered" >  if (!assertTypeEqual(limit, 'number')) {</span>
<span class="cstat-no" title="statement not covered" >    return true</span>
  }
<span class="cstat-no" title="statement not covered" >  if (!SIZE_UNIT.includes(unit)) {</span>
<span class="cstat-no" title="statement not covered" >    return true</span>
  }
<span class="cstat-no" title="statement not covered" >  return fileSize &gt; limit * SIZE[unit]</span>
}
&nbsp;
export function IGuid() <span class="fstat-no" title="function not covered" >{</span>
<span class="cstat-no" title="statement not covered" >  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) <span class="fstat-no" title="function not covered" >{</span></span>
    let r = <span class="cstat-no" title="statement not covered" >Math.random() * 16 | 0</span>
    let v = <span class="cstat-no" title="statement not covered" >c === 'x' ? r : (r &amp; 0x3 | 0x8)</span>
<span class="cstat-no" title="statement not covered" >    return v.toString(16)</span>
  })
}
&nbsp;
// 读取url的参数值
export function IQuery(name) <span class="fstat-no" title="function not covered" >{</span>
<span class="cstat-no" title="statement not covered" >  if (!assertTypeEqual(name, 'string')) {</span>
<span class="cstat-no" title="statement not covered" >    return true</span>
  }
  let reg = <span class="cstat-no" title="statement not covered" >new RegExp('(^|&amp;)' + name + '=([^&amp;]*)(&amp;|$)', 'i')</span>
  let r = <span class="cstat-no" title="statement not covered" >decodeURI(window.location.search.substr(1)).match(reg)</span>
<span class="cstat-no" title="statement not covered" >  if (r != null) <span class="cstat-no" title="statement not covered" >return decodeURI(r[2])</span></span>
<span class="cstat-no" title="statement not covered" >  return ''</span>
}
&nbsp;
// url参数转化
export function objectToUrlParamsString(obj = {}) <span class="fstat-no" title="function not covered" >{</span>
<span class="cstat-no" title="statement not covered" >  if (!isObject(obj)) {</span>
<span class="cstat-no" title="statement not covered" >    return {}</span>
  }
  let temp = <span class="cstat-no" title="statement not covered" >[]</span>
<span class="cstat-no" title="statement not covered" >  Object.keys(obj).map(key =&gt; <span class="fstat-no" title="function not covered" >{</span></span>
<span class="cstat-no" title="statement not covered" >    if (obj[key]) {</span>
<span class="cstat-no" title="statement not covered" >      temp.push(key + '=' + obj[key])</span>
    } else {
<span class="cstat-no" title="statement not covered" >      temp.push(key)</span>
    }
  })
<span class="cstat-no" title="statement not covered" >  return temp.join('&amp;')</span>
}
&nbsp;</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
  Code coverage
  generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sun Feb 24 2019 15:08:50 GMT+0800 (中国标准时间)
</div>
</div>
<script src="../../prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="../../sorter.js"></script>
</body>
</html>
